/*!
 * \autor captainpeng
 * \date 2019-12-17
 * \version 1.0
 * \copyright
 */

#include<iostream>
#include<my.hpp>

void * AllocTest(size_t size){
    void * pt = my::memFunc<int>::Alloc(size);
    std::cout<<"AllocTest size = "<<size<<", pt = "<<pt<<std::endl;
    return pt;
}

void FreeTest(void * pt){
    std::cout<<"FreeTest pt = "<<pt<<std::endl;
    return my::memFunc<int>::Free(pt);
}

int main(){
    using namespace std;
    using namespace my;
    int *p[1024];
    int num = 10;
    int i;
    my::buffer<int> b1(1024);
    my::buffer<int> b2(1024);
    my::buffer<int> b3(1024);

    std::cout<<"-----------"<<std::endl;
    for(i = 0; i < num; ++i)
        p[i] = memory::alloc<int>(1);
    while(true){
        memory::printTree();
        std::cout<<"-----------"<<std::endl;
        for(i = 0; i < num; ++i)
            std::cout<<"----- ["<<i<<"] "<<(void *)p[i]<<std::endl;
        std::cin>>i;
        if(i == -1) break;
        std::cout<<"----- delete "<<(void *)p[i]<<std::endl;
        memory::free(p[i]);
    }
    memory::printTree();
    std::cout<<"-----new test------"<<std::endl;
    {
        allocstack s;
        for(int i = 0; i < 10; ++i){
            memory::salloc<int>(s, 1, AllocTest, FreeTest);
        }
        std::cout<<s<<std::endl;
        memory::printTree();
        std::cout<<"-----1------"<<std::endl;
    }
    memory::printTree();
    std::cout<<"-----new test------"<<std::endl;
    return 0;
}
